/**
 * 
 */
package com.gr.staffpm.pages.behaviour;

import org.apache.wicket.behavior.AbstractBehavior;
import org.apache.wicket.markup.html.IHeaderResponse;

import com.gr.staffpm.pages.schedule.ExtCalendarNav;


/**
 * @author Graham Rhodes 18 Mar 2011 21:17:17
 */
public class ExtCalendarNavBehaviour extends AbstractBehavior {

    private static final long serialVersionUID = 1L;
    private final ExtCalendarNav nav;

    public ExtCalendarNavBehaviour(ExtCalendarNav nav) {
        this.nav = nav;
    }

    @Override
    public void renderHead(IHeaderResponse iHeaderResponse) {
        super.renderHead(iHeaderResponse);
        iHeaderResponse.renderOnLoadJavascript("jQuery(\".x-date-mp-month a:contains('"
                + nav.getCurrentDate().toString("MMM")
                + "')\").parent().addClass('x-date-mp-sel');"
                + "jQuery(\".x-date-mp-year a:contains('"
                + nav.getCurrentDate().toString("yyyy")
                + "')\").parent().addClass('x-date-mp-sel');"
                + "jQuery('.x-date-inner td').click(function(){"
                + "     jQuery('.x-date-inner td').removeClass('x-date-selected');"
                + "     $(this).addClass('x-date-selected');"
                + "});"
                + "jQuery('.x-date-mp-month').click(function(){"
                + "     jQuery('.x-date-mp-month.x-date-mp-sel').removeClass('x-date-mp-sel');"
                + "     $(this).addClass('x-date-mp-sel');"
                + "});"
                + "jQuery('.x-date-mp-year').click(function(){"
                + "     jQuery('.x-date-mp-year.x-date-mp-sel').removeClass('x-date-mp-sel');"
                + "     $(this).addClass('x-date-mp-sel');"
                + "});"
                + "jQuery('.x-date-mp-cancel').click(function(){"
                + "     jQuery(\".x-date-mp-month a:contains('"
                + nav.getCurrentDate().toString("MMM")
                + "')\").addClass('x-date-mp-sel');"
                + "     jQuery(\".x-date-mp-year a:contains('"
                + nav.getCurrentDate().toString("yyyy")
                + "')\").addClass('x-date-mp-sel');"
                + "})");
    }

}
